//
//  BRPayStatusViewController.m
//  BrezzeSaaS
//
//  Created by IOS on 2021/9/24.
//  Copyright © 2021 Brezze GWG. All rights reserved.
//

#import "BRPayStatusViewController.h"
#import "BRAlertCustomView.h"
#import "BRODListView.h"

@interface BRPayStatusViewController ()

@property (nonatomic,strong) UIStackView *topStack;
@property (nonatomic,strong) BRODStackCellView *bottomStack1;
@property (nonatomic,strong) BRODStackCellView *bottomStack2;

@property (nonatomic,strong) UIView *stackBGView1;
@property (nonatomic,strong) UIView *stackBGView2;

@property (nonatomic,strong) QMUIButton *btnL;
@end

@implementation BRPayStatusViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setUI];
    
    [self br_updateData];
}

#pragma mark - action --
- (void)bottomClik:(QMUIButton *)btn {
    
    if (self.status == BRPAY_FAILED) {
        
        if (btn.tag == 100) {
            // backHome
            [self backHome];
        }else {
            [self pop];
        }
        return;
    }
    if (btn.tag == 100) {
        // receipt 发票
        [self  showInputView];
    }else {
        // backHome
        [self backHome];
    }
}

- (void)showInputView {
    
    BRAlertCustomView *alert = [[BRAlertCustomView alloc] initWithFrame:self.view.bounds type:0];
    alert.titleStr = Localized(@"pay_emailReceiptText");
    alert.titleLB.font = [UIFont fontS:15];
    alert.titleLB.numberOfLines = 0;
    alert.textTF.placeholder = Localized(@"toast_requiredEmail");
    alert.textTF.maximumTextLength = 320;
    NSString *emailStr = USERManager.userModel.receiptEmail;
    alert.textTF.text = emailStr.length != 0 ? emailStr : @"";
    alert.textTF.keyboardType = UIKeyboardTypeEmailAddress;
    [alert setRightBtnTitle:Localized(@"home_confirm")];
    [self.view addSubview:alert];
    WS(weakSelf);
    alert.alertBlock = ^(NSString * _Nonnull changeText, NSInteger index, void (^ _Nonnull hidd)(BOOL)) {
        
        if (changeText.length == 0) {
            [BRHud show:Localized(@"toast_requiredEmail") inView:self.view];
            return;
        }
        if (![BRTools checkEmail:changeText]) {
            [BRHud showAuto:Localized(@"toast_validEmail") inView:self.view];
            return;
        }
        [weakSelf reqestSentToEmail:changeText succ:^(BOOL isSucc) {
            hidd(isSucc);
        }];
        
    };
    
}

- (void)reqestSentToEmail:(NSString *)email succ:(void(^)(BOOL isSucc))statusBlock {
    
    [BRHud showInView:self.view];
    NSDictionary *dic = @{@"receiptEmail":email,@"orderNo":self.dto.payOrderNo};
    [[BRRequestManager shared] POST:[BRAPI receipts] params:dic succeed:^(NSDictionary * _Nonnull dataDict, NSInteger respCode) {
        
        statusBlock(YES);
        BRUserModel *model  = USERManager.userModel;
        model.receiptEmail = email;
        USERManager.userModel = model;
        [BRHud hiddenInView:self.view];
        [BRHud showTips:Localized(@"public_success")];
        [self backHome];
        self.btnL.enabled = NO;
        
    } failed:^(NSInteger code, NSString * _Nonnull errMsg) {
        statusBlock(NO);
        [BRHud hiddenInView:self.view];
    }];
    
}

- (void)backHome {
    
    
    if (USERManager.isScanIn) {
        
        NSString *popVc = @"BRScanViewController";
        UIViewController *findVc = [self.navigationController jk_findViewController:popVc];
        if (findVc) {
            [self.navigationController jk_popToViewControllerWithClassName:popVc animated:YES];
            return;
        }
    }
    USERManager.isScanIn = NO;
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)br_updateData {
    
    BROrderDetailModel *dto = self.orderDto;
    
    NSString *str5 = @"--";
    if (!BR_StringIsEmpty(self.dto.paymentMethod) && self.status == BRPAY_SUCC) {
        NSInteger paymentMethod = [self.dto.paymentMethod integerValue];
        NSString *payByStr = Localized(@"pay_paidBy");
        if (paymentMethod == 1) {
            str5 = [NSString stringWithFormat:@"%@ %@(%@)",payByStr,Localized(@"wallet_creditCard"),self.dto.bankNo];
        }else if (paymentMethod == 4) {
            str5 = [NSString stringWithFormat:@"%@ Google",payByStr];
        }else if (paymentMethod == 3) {
            str5 = [NSString stringWithFormat:@"%@ Apple",payByStr];
        }
    }
    
    NSString *text = self.dto.failedReason;
    if (self.status == BRPAY_SUCC) {
        
        text = str5;
    }
  
    // -------------------
//    NSDecimalNumber *amount = (self.dto.type == 5) ? self.
    NSInteger type = self.dto.type;
    if (dto.lost) {
        type = 7;
    }
    BOOL hasTax = dto.tax > 0;
    if (type == 5) {
        hasTax = NO;
    }
    [self.bottomStack2 br_text:self.dto.orderNo by:0];
    [self.bottomStack2 br_text:[BRTools payType:type] by:1];
    
    [self.bottomStack2 br_title:[NSString stringWithFormat:@"%@ %.2f%%",Localized(@"pay_tax"),dto.tax] text:[BRPayManager br_amount:dto.taxAmount] by:2];
    [self.bottomStack2 br_hidden:!hasTax by:2];
    
    NSString *orderAmount = Localized(@"order_paymentAmount");
    if (hasTax) {
        orderAmount = [NSString stringWithFormat:@"%@ (%@)",orderAmount,Localized(@"pay_includingTax")];
    }
    [self.bottomStack2 br_title:orderAmount text:[BRPayManager br_amount:self.dto.amount] by:3];
    
    
    [self.bottomStack2 br_text:text by:4];
    
    if (self.dto.type == 5) return;

    NSString *timeDuration = @"";
    if (dto.useDuration == 0) {
        timeDuration = [BRTools getDurationTimeInDetail:dto.createTime formatter:@"yyyy年MM月dd日 HH:mm:ss"];
    }else {
        timeDuration = [BRTools getFormatTimeFromDurationTime:dto.useDuration];
    }
    [self br_text:timeDuration by:0];
    [self br_text:[BRPayManager br_amount:dto.orderAmount] by:1];
    
    
    // 抵扣类型：1-金额 2-时间 3-折扣
//    NSInteger couponType = dto.couponInfo.deductionType;
//    NSString *title1 = [BRStringTools br_couponsTypeStr:couponType];
//    NSString *text1 = [BRStringTools br_couponsTypeContent:dto.couponInfo];
    
    [self.bottomStack1 br_title:Localized(@"charge_card") text:[BRStringTools br_chargeCardOfTime:dto.chargeCardDuration.integerValue] by:0];
    NSString *title1 = Localized(@"menu_coupon");
    NSString *couponText = dto.userCouponInfo.deductionType == 1 ? [BRStringTools br_couponTypeTime:dto.userCouponInfo] : [BRPayManager br_amount:dto.couponAmount];

    [self.bottomStack1 br_title:title1 text:couponText by:1];
    NSString *promoText = dto.userPromoCodeInfo.deductionType == 1 ? [BRStringTools br_couponTypeTime:dto.userPromoCodeInfo] : [BRPayManager br_amount:dto.promoCodeAmount];
    [self.bottomStack1 br_title:Localized(@"pay_promoCode") text:promoText by:2];
    [self.bottomStack1 br_title:Localized(@"order_discount") text:[BRPayManager br_amount:dto.plateCouponAmount] by:3];
    
    // -------------------
    BOOL hasChargeCard = dto.chargeCardDuration.integerValue != 0;
    BOOL hasCoupon = dto.userCouponId.length != 0;
    BOOL hasPromo = dto.userPromoCodeId.floatValue != 0;
    BOOL hasDis = dto.plateCouponAmount.floatValue != 0;
    [self.bottomStack1 br_hidden:!hasChargeCard by:0];
    [self.bottomStack1 br_hidden:!hasCoupon by:1];
    [self.bottomStack1 br_hidden:!hasPromo by:2];
    [self.bottomStack1 br_hidden:!hasDis by:3];
    
    BOOL hidddenAll = !(hasCoupon || hasPromo || hasDis || hasChargeCard);
    self.stackBGView1.hidden = hidddenAll;
    if (!hidddenAll) {
        [self.stackBGView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.offset(0);
            make.top.equalTo(self.stackBGView1.mas_bottom).offset(0);
        }];
    }else {
        [self.stackBGView2 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.offset(0);
            make.top.offset(0);
        }];
    }
}

- (void)br_text:(NSString *)text by:(NSInteger)index {
    BRODListView *cell = [self.topStack viewWithTag:2000 + index];
    cell.textL.text = text;
}

#pragma mark - SET UI --
- (void)setUI {
    
    
    [self br_createTop:@"" imageStr:@""];
    
//    self.view.backgroundColor = UIColor.whiteColor;
    
    NSString *payStr = Localized(@"order_paymentMethod");
    NSString *stateStr = Localized(@"pay_paySucc");
    NSString *imgStr = @"payment_succ";
    UIColor *titleC = kColorMain;
    if (self.status == BRPAY_FAILED) {
        payStr = Localized(@"pay_errorMsg");
        stateStr = Localized(@"pay_payFail");
        imgStr = @"payment_failed";
        titleC = kColorTitle889;
    }
   
    CGFloat bH = 72 + kSafeAreaBottomHeight;
    UIScrollView *sView = [[UIScrollView alloc] init];
    sView.showsVerticalScrollIndicator = NO;
    sView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:sView];
    [sView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(0);
        make.left.offset(0);
        make.top.offset(kSafeAreaTopHeight);
        make.bottom.equalTo(self.view).offset(-bH);
    }];
    
    UIView *contView = [[UIView alloc] init];
    contView.backgroundColor = UIColor.clearColor;
    [sView addSubview:contView];
    [contView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(kScreenWidth);
        make.edges.offset(0);
    }];
    
    CGFloat img_w = 120;
    
    UIImageView *statusImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, img_w, img_w)];
    statusImg.image =  UIImageMake(imgStr);
    [contView addSubview:statusImg];
    [statusImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(img_w);
        make.top.offset(0);
        make.centerX.offset(0);
    }];
    QMUILabel *succL = [BRToolsView br_label:stateStr textColor:titleC font:[UIFont fontH:20]];
    [contView addSubview:succL];
    [succL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(statusImg.mas_bottom);
    }];
    
    [self br_addBottomUI];
    // -----------内容区域-----------
    CGFloat mX = 14;
    UIView *topView = [[UIView alloc] init];
    topView.backgroundColor = UIColor.whiteColor;
    topView.layer.cornerRadius = 10;
    topView.layer.masksToBounds = YES;
    [contView addSubview:topView];
    
    QMUILabel *payDetailL = [BRToolsView br_label:Localized(@"order_paymentDetails2") textColor:kColorTitle font:[UIFont fontS:17]];
    [contView addSubview:payDetailL];
    
    NSArray *billingTitles = @[Localized(@"pay_transactionNo"),
                               Localized(@"home_for"),
                               Localized(@"pay_tax"),
                               Localized(@"order_paymentAmount"),
                               payStr,];
    [self.bottomStack2 br_addList:billingTitles imgs:@[]];
    if (self.dto.type == 5 || self.dto.type == 19) {
      
        [topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(statusImg.mas_bottom).offset(80);
            make.left.offset(mX);
            make.right.offset(-mX);
            make.bottom.offset(-12);
        }];
        //Payment details
        [payDetailL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(24);
            make.bottom.equalTo(topView.mas_top).offset(-10);
        }];
        
        QMUILabel *billL = [BRToolsView br_label:Localized(@"pay_billing") textColor:kColorTitle font:[UIFont fontS:15]];
        [topView addSubview:billL];
        [billL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(20);
            make.top.offset(14);
        }];
        [topView addSubview:self.bottomStack2];
        [self.bottomStack2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.offset(46);
            make.left.offset(0);
            make.right.offset(0);
            make.bottom.offset(0);
        }];
        
        return;
    }
    
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(statusImg.mas_bottom).offset(50);
        make.left.offset(mX);
        make.right.offset(-mX);
    }];
    
    UIView *centView = [[UIView alloc] init];
    centView.backgroundColor = UIColor.whiteColor;
    centView.layer.cornerRadius = 10;
    centView.layer.masksToBounds = YES;
    [contView addSubview:centView];
    [centView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(topView.mas_bottom).offset(44);
        make.left.offset(mX);
        make.right.offset(-mX);
        make.bottom.offset(-20);
    }];
    
    self.stackBGView1 = [[UIView alloc] init];
    self.stackBGView2 = [[UIView alloc] init];
    [centView addSubview:self.stackBGView1];
    [centView addSubview:self.stackBGView2];
    
    [self.stackBGView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
    }];
    [self.stackBGView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.offset(0);
        make.top.equalTo(self.stackBGView1.mas_bottom).offset(0);
    }];
    
   
    [payDetailL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(24);
        make.bottom.equalTo(centView.mas_top).offset(-10);
    }];
    
    CGFloat mX20 = 20;
    NSArray *titles = @[Localized(@"home_duration"),
                        Localized(@"order_orderAmount"),];
    for (int i = 0; i < titles.count; i++) {
        
        BRODListView *cell = [[BRODListView alloc] init];
        [self.topStack addArrangedSubview:cell];
//        cell.textL.font = [UIFont fontS:15];
        cell.tag = 2000 + i;
        cell.titleL.text = titles[i];
        cell.line.hidden = i == 1;
    }
    [topView addSubview:self.topStack];
    [self.topStack mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.offset(0);
        make.right.offset(0);
        make.top.bottom.offset(0);
    }];
    
    QMUILabel *couponTitle = [BRToolsView br_label:Localized(@"pay_couponAndDiscount") textColor:kColorTitle font:[UIFont fontS:15]];
    [self.stackBGView1 addSubview:couponTitle];
    [couponTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(mX20);
        make.top.offset(14);
    }];
    
    [self.bottomStack1 br_addList:@[@"--",@"--",@"--",@"--"] imgs:@[@"1",@"1",@"1",@"1"]];
    [self.bottomStack1 br_img:@"charge_type" by:0];
    [self.stackBGView1 addSubview:self.bottomStack1];
    [self.bottomStack1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(46);
        make.left.offset(mX20);
        make.right.offset(-mX20);
        make.bottom.offset(0);
    }];
    
    UIView *line = [BRToolsView getLineView];
    [self.stackBGView1 addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.mas_equalTo(0.5);
        make.bottom.offset(0);
    }];
    
    QMUILabel *billL = [BRToolsView br_label:Localized(@"pay_billing") textColor:kColorTitle font:[UIFont fontS:15]];
    [self.stackBGView2 addSubview:billL];
    [billL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(mX20);
        make.top.offset(14);
    }];
    [self.stackBGView2 addSubview:self.bottomStack2];
    [self.bottomStack2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(46);
        make.left.offset(0);
        make.right.offset(0);
        make.bottom.offset(0);
    }];
   
   
}

- (void)br_addBottomUI {
    
    CGFloat bH = 72 + kSafeAreaBottomHeight;
    // -------底部按钮-------
    UIView *bottomV = [[UIView alloc] init];
    bottomV.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:bottomV];
    [bottomV br_addBaseShadow];
    [bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(bH);
        make.bottom.left.right.offset(0);
        
    }];
    
    UIStackView *stack = [[UIStackView alloc] init];
    stack.spacing = 10;
    stack.distribution = UIStackViewDistributionFillEqually;
    [bottomV addSubview:stack];
    [stack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-14);
        make.left.offset(14);
        make.top.offset(10);
        make.height.mas_equalTo(52);
    }];
    
    NSString *leftStr = Localized(@"order_receipt");
    NSString *home =  Localized(@"order_homePage");
    if (self.status == BRPAY_FAILED) {
        home = Localized(@"home_go2pay");
        leftStr = Localized(@"order_homePage");
    }
    if (USERManager.isScanIn && self.status != BRPAY_FAILED) home = Localized(@"home_scan2rent");
   
    QMUIButton *btnL = [[QMUIButton alloc] init];
    [btnL setTitle:leftStr forState:UIControlStateNormal];
    [btnL setTitleColor:kColorMain forState:UIControlStateNormal];
    btnL.titleLabel.font = [UIFont fontS:17];
    btnL.layer.cornerRadius = 26;
    btnL.layer.masksToBounds = YES;
    btnL.layer.borderColor = kColorMain.CGColor;
    btnL.layer.borderWidth = 1;
    [stack addArrangedSubview:btnL];
    [btnL mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.height.mas_equalTo(52);
    }];
    
    QMUIButton *btnR = [BRToolsView br_btnBGImg:home];
    btnR.titleLabel.adjustsFontSizeToFitWidth = YES;
    [stack addArrangedSubview:btnR];
    [btnR mas_makeConstraints:^(MASConstraintMaker *make) {
     
        make.height.mas_equalTo(52);
    }];
    
    btnL.tag = 100;
    btnR.tag = 101;
    
    [btnR addTarget:self action:@selector(bottomClik:) forControlEvents:UIControlEventTouchUpInside];
    [btnL addTarget:self action:@selector(bottomClik:) forControlEvents:UIControlEventTouchUpInside];
    
    [bottomV br_addBaseShadow];
    
    _btnL = btnL;
    
    if (self.dto && self.status != BRPAY_FAILED) {
        
        if (self.isFree) {
            btnL.hidden = YES;
        }
    }
}


- (UIStackView *)topStack {
    
    if (_topStack == nil) {
        
        _topStack = [[UIStackView alloc] init];
        _topStack.axis = UILayoutConstraintAxisVertical;
        
    }
    return _topStack;
}
- (BRODStackCellView *)bottomStack1 {
    
    if (_bottomStack1 == nil) {
        
        _bottomStack1 = [[BRODStackCellView alloc] init];
        
    }
    return _bottomStack1;
}

- (BRODStackCellView *)bottomStack2 {
    if (_bottomStack2 == nil) {
        _bottomStack2 = [[BRODStackCellView alloc] init];
    }
    return _bottomStack2;
}


- (void)createContentView {
    
    CGFloat width = kScreenWidth - 64;
    CGFloat top_y = kScale414(89);
    UIView *shadow = [[UIView alloc] init];
    [self.view addSubview:shadow];
    [shadow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(width);
        make.height.mas_equalTo(28);
        make.left.equalTo(self.view).offset(32);
        make.top.equalTo(self.view).offset(top_y + KStatusBarHeight);
    }];
    
//    shadow.layer.cornerRadius = 14;
//    shadow.clipsToBounds = YES;
    
    // 横条
    UIView *view = [[UIView alloc] init];
    view.frame = CGRectMake(0,0,width,28);
    view.layer.cornerRadius = 14;
    view.clipsToBounds = YES;
    [shadow addSubview:view];
    
    shadow.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.26].CGColor;
    shadow.layer.shadowOffset = CGSizeMake(0,5);
    shadow.layer.shadowOpacity = 1;
    shadow.layer.shadowRadius = 8;
    [view layoutIfNeeded];

    // gradient br_payStatusLineBGColors
    CAGradientLayer *gl2 = [BRTools gradientLayerWithColors:[BRThemeManage br_payStatusLineBGColors] rect:CGRectMake(view.qmui_left,view.qmui_top,view.qmui_width,view.qmui_height)];
    
    [view.layer addSublayer:gl2];
    

    UIView *blackView = [[UIView alloc] init];
    blackView.backgroundColor = UIColorBlack;
    blackView.layer.cornerRadius = 4;
    blackView.layer.masksToBounds = YES;
    [self.view addSubview:blackView];
    [blackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(width - 28);
        make.height.mas_equalTo(8);
        make.left.equalTo(self.view).offset(46);
        make.top.equalTo(self.view).offset(top_y + 10 + KStatusBarHeight);
    }];
    
    UIScrollView *sView = [[UIScrollView alloc] init];
    sView.showsVerticalScrollIndicator = NO;
    sView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:sView];
    [sView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(width - 40);
        make.left.equalTo(blackView).offset(6);
        make.top.equalTo(blackView).offset(5);
        make.bottom.equalTo(self.view);
    }];
    
//    CGFloat height = 400.0 - 24;
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = UIColorClear;
    [sView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(width - 40);
//        make.left.equalTo(blackView).offset(6);
//        make.top.equalTo(blackView).offset(5);
        make.edges.equalTo(sView);
    }];
    bgView.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.07].CGColor;
    bgView.layer.shadowOffset = CGSizeMake(0,6);
    bgView.layer.shadowOpacity = 1;
    bgView.layer.shadowRadius = 16;
    
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = UIColor.qd_backgroundColor2;
    contentView.layer.cornerRadius = 4;
    contentView.layer.masksToBounds = YES;
    [bgView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(width - 40);
//        make.height.mas_equalTo(height);
        make.left.equalTo(bgView).offset(0);
        make.top.equalTo(bgView).offset(0);
        make.bottom.equalTo(bgView).offset(-(104 + kSafeAreaBottomHeight));
    }];
//    [contentView layoutIfNeeded];
    
    
    // 内容控件
    UIImageView *statusImg = [[UIImageView alloc] init];
    statusImg.image = self.status == BRPAY_SUCC ? UIImageMake(@"payment_succ") : UIImageMake(@"payment_failed");
    statusImg.backgroundColor = self.status == BRPAY_SUCC ? UIColor.qd_tintColor3 : UIColor.qd_tintColor9;
    statusImg.layer.cornerRadius = 26.;
    statusImg.layer.masksToBounds = YES;
    [contentView addSubview:statusImg];
    [statusImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(52);
        make.top.equalTo(contentView).offset(34);
        make.centerX.equalTo(contentView);
    }];
    QMUILabel *statusLB = [[QMUILabel alloc] init];
    statusLB.text = self.status == BRPAY_SUCC ? Localized(@"Payment_success") : Localized(@"Payment_failed");
    statusLB.textColor = UIColor.qd_titleTextColor;
    statusLB.font = [UIFont br_fontB:17];
    [contentView addSubview:statusLB];
    [statusLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(statusImg.mas_bottom).offset(18);
        make.centerX.equalTo(contentView);
    }];
    
    NSString *paymentStr = Localized(@"Order_amount");
    NSString *payStatusStr = Localized(@"Payment_errorMessage");
    if (self.status == BRPAY_SUCC) {
//        paymentStr = Localized(@"Order_amount");
        payStatusStr = Localized(@"Payment_method");
    }

    NSArray *contents = @[Localized(@"Payment_transID"),Localized(@"Payment_time"),paymentStr,Localized(@"Payment_types"),payStatusStr];
    NSArray *contText = @[];
    if (self.dto) {
        
        NSString *str1 = self.dto.orderNo;
        NSString *str2 = [BRTools getTimeFromTimestamp:self.dto.paymentTime.integerValue formatter:kBRDateFormatterdMy];
        NSString *str3 = [BRPayManager br_amount:self.dto.amount];
        NSString *str4 = [BRTools payType:self.dto.type];
        NSString *payByStr = Localized(@"pay_paidBy");
        NSString *str5 = [NSString stringWithFormat:@"%@ Apple",payByStr];
        if (self.status == BRPAY_FAILED) {
            str5 = self.dto.failedReason;
        }else {
            if (BR_StringIsEmpty(self.dto.paymentMethod)) {
                str5 = @"--";
            }else {
                NSInteger paymentMethod = [self.dto.paymentMethod integerValue];
                if (paymentMethod == 1) {
                    str5 = [NSString stringWithFormat:@"%@ %@(%@)",payByStr,Localized(@"payment_card"),self.dto.bankNo];
                }else if (paymentMethod == 2) {
                    str5 = [NSString stringWithFormat:@"%@ FamilyCircle",payByStr];
                }else if (paymentMethod == 4) {
                    str5 = [NSString stringWithFormat:@"%@ Google",payByStr];
                }else if (paymentMethod == 5) {
                    str5 = [NSString stringWithFormat:@"%@ Paypal",payByStr];
                }
            }
            
        }
        
//        str5 = @"AT - NSLocalizedDescription=The request timed out., NSErrorFailingURLStringKey=https://device-provisioning.googleapis.com/checkin, NSErrorFailingURLKey=https://device-provisioning.googleapis.com/checkin, _kCFStreamErrorDomainKey=4}";
        
        contText = @[str1,str2,str3,str4,str5];
        
    }
    /// imgBottom 85 + 40 *i
    for (int i = 0; i < contents.count; i++) {
        QMUILabel *contLB = [[QMUILabel alloc] init];
        contLB.text = contents[i];
        if (contText.count > i) {
            NSString *symbStr = @": " ;
            contLB.text = [NSString stringWithFormat:@"%@%@%@",contents[i],symbStr,contText[i]];
        }
        contLB.textColor = UIColor.qd_titleTextColor2;
        contLB.font = [UIFont br_fontM:14];
        contLB.tag = 200 + i;
        contLB.numberOfLines = i == 4 ? 0 : 2;
        [contentView addSubview:contLB];
        [contLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(statusImg.mas_bottom).offset(85 + 40 *i);
            make.left.equalTo(contentView).offset(24);
            make.right.equalTo(contentView).offset(-24);
            if (i == contents.count - 1) {
                make.bottom.equalTo(contentView.mas_bottom).offset(-(24));
            }
        }];
    }
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 146, width, 0.5)];
    line.backgroundColor = UIColor.qd_lineColor2;
    [contentView addSubview:line];
    
    UIView *bottomView = [[UIView alloc] init];
    bottomView.backgroundColor = UIColor.qd_backgroundColor2;
    [bgView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(contentView.mas_bottom).offset(-4);
        make.width.mas_equalTo(width - 40);
        make.height.mas_equalTo(24);
        make.left.equalTo(bgView).offset(0);
    }];
    
    {
        [bottomView layoutIfNeeded];
        NSInteger count = (width - 40) / 16;
        // 创建一个全屏大的path
        UIBezierPath *bpath = [UIBezierPath bezierPathWithRoundedRect:bottomView.bounds cornerRadius:0];
        for (int i = 0; i < count; i++) {
            UIBezierPath *pa = [UIBezierPath bezierPathWithRoundedRect:CGRectMake( 6 + (i * 16), 24 - 5, 10, 10) cornerRadius:5];
    //        CGRectMake(contentView.mj_x + 4 + (i * 12), 407, 12, 12)
            [bpath appendPath:pa];
        }
        [bpath setUsesEvenOddFillRule:YES];
        
        //创建一个CAShapeLayer 图层
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.path = bpath.CGPath;
        shapeLayer.fillRule = kCAFillRuleEvenOdd;
        
         //添加图层蒙板
        bottomView.layer.mask = shapeLayer;
    }
    
    // 底部按钮
    NSString *home =  Localized(@"order_homePage");
    NSString *leftStr = Localized(@"order_receipt");
    if (self.status == BRPAY_FAILED) {
        leftStr = home;
        home = Localized(@"Report_goToPay");
    }
    for (int i = 0; i < 2; i++) {
        QMUIButton *btn = [[QMUIButton alloc] init];
        if (i == 0) {
            [btn setTitle:leftStr forState:UIControlStateNormal];
            [btn setTitleColor:UIColor.qd_rentLBTitleColor forState:UIControlStateNormal];
            [btn setBackgroundColor:UIColorClear];
            btn.layer.borderColor = UIColor.qd_rentLBTitleColor.CGColor;
            btn.layer.borderWidth = 1;
        }else {
            [btn setTitle:home forState:UIControlStateNormal];
            [btn setTitleColor:UIColorWhite forState:UIControlStateNormal];
//            [btn setBackgroundColor:UIColor.qd_tintColor];
            [btn setBackgroundImage:UIImage.qd_homeScanBtnImage forState:UIControlStateNormal];
            btn.layer.masksToBounds  = YES;
        }
        btn.titleLabel.font = [UIFont br_fontB:16];
        btn.tag = 100 + i;
        [self.view addSubview:btn];
        CGFloat btnWidth = (kScreenWidth - 48) / 2.0;
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(btnWidth);
            make.height.mas_equalTo(50);
            make.left.equalTo(self.view).offset(16 + i * (btnWidth + 16));
            make.bottom.equalTo(self.view).offset(-(kSafeAreaBottomHeight +25.));
        }];
        [btn addTarget:self action:@selector(bottomClik:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    
    
}

/**
*画虚线
@param lineView 视图
@param lineLength 单个虚线大小
@param lineSpacing 间隔
@param lineColor 虚线颜色
*/
- (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor {
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setBounds:lineView.bounds];
    [shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
    [shapeLayer setFillColor:[UIColor clearColor].CGColor];
    //  设置虚线颜色为blackColor
    [shapeLayer setStrokeColor:lineColor.CGColor];
    //  设置虚线宽度
    [shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
    [shapeLayer setLineJoin:kCALineJoinRound];
    //  设置线宽，线间距
    [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
//    UIBezierPath *path2 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2, 1) cornerRadius:.5];
//    shapeLayer.path = path2.CGPath;
    //  设置路径
    CGMutablePathRef path = CGPathCreateMutable();
//    CGMutablePathRef path = CGPathCreateMutableCopy(path2.CGPath);
    
    CGPathMoveToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL,CGRectGetWidth(lineView.frame), 0);
    [shapeLayer setPath:path];
    CGPathRelease(path);
    //  把绘制好的虚线添加上来
    [lineView.layer addSublayer:shapeLayer];
}

- (BOOL)preferredNavigationBarHidden {
    return YES;
}

- (BOOL)forceEnableInteractivePopGestureRecognizer {
    // 屏蔽右滑返回
    return NO;

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

@implementation BRPayStatusDarkView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = UIColorClear;
        [self setUI];
    }
    return self;
}

- (void)setUI {
    
    UIColor *color = UIColorMake(79, 128, 255);//4f80ff
    if (self.status != BRPAY_SUCC) {
        //#FD5849
        color = UIColorMake(253, 88, 73);
    }
    UIView *centView = [[UIView alloc] init];
    centView.backgroundColor = color;
    centView.layer.cornerRadius  = 128.;
    centView.layer.masksToBounds = YES;
    [self addSubview:centView];
    [centView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(256);
        make.centerX.equalTo(self);
        make.top.equalTo(self).offset(20 + KStatusBarHeight);
    }];
    
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *shadowView = [[UIVisualEffectView alloc] initWithEffect:effect];
    [self addSubview:shadowView];
    [shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
}

@end
